/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.gov.ana.facade;

import br.gov.ana.entities.StatusDoc;
import java.math.BigDecimal;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author lucas.nunes
 */
@Stateless
public class StatusDocFacade extends AbstractFacade<StatusDoc> {

    @PersistenceContext(unitName = "ResolucaoConjunta032010PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public StatusDocFacade() {
        super(StatusDoc.class);
    }

    public StatusDoc findBySdcId(BigDecimal sdcId) {
        try {
            Query q = em.createNamedQuery("StatusDoc.findBySdcId").setParameter("sdcId", sdcId);
            q.setMaxResults(1);
            return (StatusDoc) q.getSingleResult();
        } catch (Exception e) {
            return null;
        }
    }

    public List<StatusDoc> findStatusNotaTecnica() {
        try{
            Query q = em.createQuery("SELECT sd FROM StatusDoc sd WHERE sd.sdcId in (:aprovado , :reprovado) ORDER BY sd.sdcId");            
            q.setParameter("aprovado",new BigDecimal("1"));
            q.setParameter("reprovado",new BigDecimal("3"));
            return (List<StatusDoc>)q.getResultList();
        } catch (Exception e){
            return null;
        }
    }

    public List<StatusDoc> findStatusCartaExterna() {
         try{
            Query q = em.createQuery("SELECT sd FROM StatusDoc sd WHERE sd.sdcId = :respondido ORDER BY sd.sdcId");
            q.setParameter("respondido",new BigDecimal("4"));
            
            return (List<StatusDoc>)q.getResultList();
        } catch (Exception e){
            return null;
        }
    }
}
